package com.xm.socket;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

@Slf4j
public class ClientListener2 implements Runnable {
    private final Socket socket;
    private final int i;
    public ClientListener2(Socket socket, int i) {
        this.socket = socket;
        this.i = i;
    }

    @Override
    public void run() {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
            String message;
            while ((message = in.readLine()) != null) {
                log.info("Received：{}", message);
                for (PrintWriter client : Server.clients) {
                    client.println(message);
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
